﻿using Common;
using Common.Consts;
using Common.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using WinServiceFileListener.Consts;

namespace WinServiceFileListener
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] services)
        {
            GlobalIniReadWrite();
            FolderListenerIniReadWrite();
            FileListenerIniReadWrite();

            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new FolderListener(),
                new FileListener()
            };
            ServiceBase.Run(ServicesToRun);

        }

        /// <summary>
        /// 全局服务初始化Ini的值
        /// </summary>
        public static void GlobalIniReadWrite()
        {
            IniConst.IsDebug = IniHelper.ReadOrWrite(Sections.IsDebug, "F", "是否开启调试模式：T/F");
            IniConst.LogSaveDay = Convert.ToInt32(IniHelper.ReadOrWrite(Sections.LogSaveDay, "3", "日志保留天数"));
        }
        /// <summary>
        /// FolderListener初始化Ini的值
        /// </summary>
        public static void FolderListenerIniReadWrite()
        {
            IniConst.FolderListenPath = IniHelper.ReadOrWrite(Sections.FolderListenPath, @"E:\", "监听文件夹路径");
            IniConst.FolderListenPathKey = IniHelper.ReadOrWrite(Sections.FolderListenPathKey, "bin 接口 AppPagess", "只监听带有关键字的路径（有多个以空格隔开）");
            IniConst.FolderFilterPathKey = IniHelper.ReadOrWrite(Sections.FolderFilterPathKey, "", "过滤掉关键字中包含的路径（有多个以空格隔开）");
        }
        /// <summary>
        /// FileListener初始化Ini的值
        /// </summary>
        public static void FileListenerIniReadWrite()
        {
            IniConst.FileListenPath = IniHelper.ReadOrWrite(Sections.FileListenPath, @"E:\Company", "监听文件路径");
            IniConst.FileListenPathKey = IniHelper.ReadOrWrite(Sections.FileListenPathKey, "Debug", "监听文件路径的关键字（有多个以空格隔开）");
            IniConst.FileName = IniHelper.ReadOrWrite(Sections.FileName, "Common.dll Common.exe", "只复制指定文件（有多个以空格隔开）");
            IniConst.CustomSavePath = IniHelper.ReadOrWrite(Sections.CustomSavePath, "", "自定义保存路径");
        }
    }
}
